# coding:utf-8

import uuid

from flask import request, jsonify, current_app

from . import enterprise_bp


@enterprise_bp.route('/ajax/upload_img', methods=['POST'])
def ajax_upload_img():
    """
    created by chenhj at 2018/5/22

    """
    key = uuid.uuid4().hex
    try:
        url = current_app.qiniu.upload(key, request.files['file'].getvalue())
    except AttributeError:
        # 防止大文件
        url = current_app.qiniu.upload(key, request.files['file'].stream.read())
    return jsonify({
        'key': key,
        'url': url
    })
